package epam.generics.fruit;

import java.awt.Color;

/**
 * Simple Fruit Hierarchy
 *
 * @version 1.0 Build 28.04.2014
 * @author Yuriy Miedviediev
 */
public abstract class Fruit implements Comparable<Fruit> {
    Color color;
    Integer amount;

    public static final int HASHSALT = 31;

    public Color getColor() {
        return this.color;
    }

    public void setColor(Color c) {
        this.color = c;
    }

    public int getAmount() {
        return this.amount;
    }

    public void setAmount(int amt) {
        this.amount = amt;
    }

    @Override
    public int compareTo(Fruit other) {
        return this.amount.compareTo(other.getAmount());
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        Fruit fruit = (Fruit) o;

        if (!amount.equals(fruit.amount)) {
            return false;
        }
        if (!color.equals(fruit.color)) {
            return false;
        }

        return true;
    }

    @Override
    public int hashCode() {
        int result = color.hashCode();
        result = HASHSALT * result + amount.hashCode();
        return result;
    }
}